package com.test1230pm;

public class Test03 {
    public static void main(String[] args) {
        // (3)设计一个公司类和员工类
        // 场景：员工张三在IBM公司工作、员工李四在HP公司工作
        // 要求：根据需求创建员工和公司对象、并能表示出员工和公司之间的关联关系、打印员工以及所在公司的信息
        Company com1 = new Company("IBM");
        Employ emp1 = new Employ("张三",com1);
        emp1.print();
        String s = emp1.toString();
        System.out.println(s);


        Company com2 = new Company("HP");
        Employ emp2 = new Employ("张三",com2);
        emp2.print();
        String s1 = emp2.toString();
        System.out.println(s1);

    }
}
class Company{
    private String com_name;

    public Company(String com_name) {
        this.com_name = com_name;
    }

    public String getCom_name() {
        return com_name;
    }

    public void setCom_name(String com_name) {
        this.com_name = com_name;
    }

    @Override
    public String toString() {
        return com_name ;

    }
}
class Employ{
    private String name;
    private Company com;

    public Employ() {
    }

    public Employ(String name, Company com) {
        this.name = name;
        this.com = com;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Company getCom() {
        return com;
    }

    public void setCom(Company com) {
        this.com = com;
    }

    @Override
    public String toString() {
        return
                "员工:" + name +
                ", 公司:" + com;

    }

    public void print(){
        System.out.println("员工"+name+"在"+com.getCom_name()+"公司工作");
    }

}